
package com.yimixian.app.viewholder;

import com.yimixian.app.R;
import com.yimixian.app.model.ValidatedOrder;
import com.ymx.sdk.widget.recyclerview.viewholder.AbsViewHolder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class ChooseCouponViewHolder extends AbsViewHolder {
    @InjectView(R.id.cb_coupon)
    ImageView mCbCoupon;
    @InjectView(R.id.tv_time)
    TextView mTvTime;
    @InjectView(R.id.tv_fruit_coupon_yuan)
    TextView mTvFruitCouponYuan;
    @InjectView(R.id.tv_fruit_coupon_price)
    TextView mTvFruitCouponPrice;
    @InjectView(R.id.tv_fruit_coupon_title_sub)
    TextView mTvFruitCouponTitleSub;
    @InjectView(R.id.tv_fruit_coupon_title)
    TextView mTvFruitCouponTitle;
    @InjectView(R.id.rl_coupon_item)
    RelativeLayout mRlCouponItem;
    @InjectView(R.id.rl_head_title)
    RelativeLayout mRlHeadTitle;
    @InjectView(R.id.iv_line)
    ImageView mIvLine;
    public ChooseCouponViewHolder(View itemView, Context context) {
        super(itemView, context);
        ButterKnife.inject(this, itemView);
    }

    @Override
    public void bindItemData(Object data) {
        if (data instanceof ValidatedOrder.Bonus) {
            ValidatedOrder.Bonus itemData = (ValidatedOrder.Bonus) data;
            if (itemData.isChecked()) {
                mCbCoupon.setImageResource(R.drawable.checkbox_p);
            } else {
                mCbCoupon.setImageResource(R.drawable.checkbox_n);
            }
            mTvFruitCouponPrice.setText(itemData.getDiscount() + "");
            mTvFruitCouponTitle.setText(itemData.getSubTitle());
            mTvFruitCouponTitleSub.setText(itemData.getTitle());
            mTvTime.setText(itemData.getDuration());
            if (itemData.isUsable()) {
                mCbCoupon.setVisibility(View.VISIBLE);
                mTvFruitCouponTitleSub.setBackgroundResource(R.color.orange_headear);
                mIvLine.setBackgroundResource(R.drawable.coupon_line);
                mTvFruitCouponYuan.setTextColor(mContext.getResources().getColor(
                        R.color.orange_headear));
                mTvFruitCouponPrice.setTextColor(mContext.getResources().getColor(
                        R.color.orange_headear));
                mTvFruitCouponTitle.setTextColor(mContext.getResources().getColor(
                        R.color.sub_title_black));
                mTvFruitCouponTitleSub.setTextColor(mContext.getResources().getColor(
                        R.color.white));
                mTvTime.setTextColor(mContext.getResources().getColor(R.color.coupon_grey_new));
                mRlCouponItem.setBackgroundResource(R.drawable.coupon_item_bg);

            } else {
                mCbCoupon.setVisibility(View.INVISIBLE);
                mTvFruitCouponTitleSub.setBackgroundResource(R.color.coupon_gery);
                mIvLine.setBackgroundResource(R.drawable.coupon_line_disable);
                mTvFruitCouponYuan.setTextColor(mContext.getResources().getColor(
                        R.color.coupon_gery));
                mTvFruitCouponPrice.setTextColor(mContext.getResources().getColor(
                        R.color.coupon_gery));
                mTvFruitCouponTitle.setTextColor(mContext.getResources().getColor(
                        R.color.coupon_gery));
                mTvFruitCouponTitleSub.setTextColor(mContext.getResources().getColor(
                        R.color.white));
                mTvTime.setTextColor(mContext.getResources().getColor(
                        R.color.coupon_grey_new));
                mRlCouponItem.setBackgroundResource(R.drawable.coupon_item_bg_disable);
            }
        }

    }
}
